/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.lczyfy.idcp.modules.sys.vueweb;

import com.google.common.collect.Lists;
import com.lczyfy.idcp.common.persistence.Page;
import com.lczyfy.idcp.common.utils.ApiResultUtils;
import com.lczyfy.idcp.common.utils.ResponseCode;
import com.lczyfy.idcp.common.utils.ServerResponse;
import com.lczyfy.idcp.common.web.BaseController;
import com.lczyfy.idcp.modules.sys.entity.Log;
import com.lczyfy.idcp.modules.sys.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 日志Controller
 * @author ThinkGem
 * @version 2013-6-2
 */
@Api(value = "log")
@RestController
@RequestMapping(value = "${apiPath}/sys/log")
public class LogVueController extends BaseController {

	@Autowired
	private LogService logService;
	@ResponseBody
	@RequestMapping(value = "search", method = RequestMethod.GET)
	@ApiOperation(value = "获取组织机构树形图")
	public ServerResponse<List<Map<String, Object>>> search(@RequestParam(required=true) int pageNo, @RequestParam(required=true) int pageSize, @RequestParam(required=false) Date beginDate, @RequestParam(required=false) Date endDate
	 , @RequestParam(required=false) String requestUri, @RequestParam(required=false) String title, @RequestParam(required=false) String exception) {
		List<Map<String, Object>> mapList = Lists.newArrayList();
		Log log = new Log();
		log.setBeginDate(beginDate);
		log.setEndDate(endDate);
		log.setTitle(title);
		log.setRequestUri(requestUri);
		log.setException(exception);
        Page<Log> page = logService.findVue(new Page<Log>(pageNo,pageSize), log);
		Map<String, Object> map = ApiResultUtils.getBaseMapSuccess();
		map.put("page", page.getList());
		map.put("pageNo", page.getPageNo());
		map.put("count", page.getCount());
		map.put("totalPage",page.getTotalPage());
		mapList.add(map);
        return new ServerResponse(ResponseCode.SUCCESS.getCode(), mapList);
	}

}
